#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""

@author: Nicholas Drachman
"""

from advMSplot import *
matplotlib.rcParams['svg.fonttype'] = 'none'

''' Glutathione '''

log_file_path = 'Fig 2/c/glutathione/10. JAN 12 2018 15-28/JAN 12 2018 15-28.log' # log file path for oglutathione (GSH) here
cdf_file_path = 'Fig 2/c/glutathione/10. JAN 12 2018 15-28/JAN 12 2018 15-28.cdf' # CDF file path for glutathione (GSH) here
tsv_file_path = 'Fig 2/c/glutathione/10. JAN 12 2018 15-28/ivpt10.tsv' # ivpt file path for glutathione (GSH) here

# Process glutathione spec
tsv_data = readIVPT(tsv_file_path)
mz_bins, combined_spec_data = process_cdf_file(cdf_file_path,log_file_path)
combined_data = combineFiles(tsv_data, combined_spec_data, mz_bins)

scan_start, scan_end = 7000,8000
spec_glu = sum_intensity_for_scan_range(combined_data, scan_start, scan_end)


mz_glu = spec_glu[0]
A_glu = spec_glu[1]

N = 55
mzsmooth_glu = np.convolve(mz_glu,np.ones(N)/N, mode = 'same')
Asmooth_glu = np.convolve(A_glu,np.ones(N)/N, mode = 'same')


''' s-nitrosoglutathione '''


log_file_path = 'Fig 2/c/s-nitrosoglutathione/30. MAR 23 2018 9-41/MAR 23 2018 9-41.log' # log file path for s-nitrosoglutathione (GSNO) here
cdf_file_path = 'Fig 2/c/s-nitrosoglutathione/30. MAR 23 2018 9-41/MAR 23 2018 9-41.cdf' # CDF file path for s-nitrosoglutathione (GSNO) here
tsv_file_path = 'Fig 2/c/s-nitrosoglutathione/30. MAR 23 2018 9-41/ivpt30.tsv' # ivpt file path for s-nitrosoglutathione (GSNO) here

# Process s-nitrosoglutathione spectrum
tsv_data = readIVPT(tsv_file_path)
mz_bins, combined_spec_data = process_cdf_file(cdf_file_path,log_file_path)
combined_data = combineFiles(tsv_data, combined_spec_data, mz_bins)

scan_start, scan_end = 6000,13000
spec_nitro = sum_intensity_for_scan_range(combined_data, scan_start, scan_end)


mz_nitro = spec_nitro[0]
A_nitro = spec_nitro[1]

N = 35
mzsmooth_nitro = np.convolve(mz_nitro,np.ones(N)/N, mode = 'same')
Asmooth_nitro = np.convolve(A_nitro,np.ones(N)/N, mode = 'same')



''' s-acetylglutathione '''


log_file_path = 'Fig 2/c/s-acetylglutathione/23. MAR 20 2018 20-16/MAR 20 2018 20-16.log' # log file path for s-acetylglutathione (SAG) here
cdf_file_path = 'Fig 2/c/s-acetylglutathione/23. MAR 20 2018 20-16/MAR 20 2018 20-16.cdf' # CDF file path for s-acetylglutathione (SAG) here
tsv_file_path = 'Fig 2/c/s-acetylglutathione/23. MAR 20 2018 20-16/ivpt23.tsv' # ivpt file path for s-acetylglutathione (SAG) here

# Process s-acetylglutathione spectrum
tsv_data = readIVPT(tsv_file_path)
mz_bins, combined_spec_data = process_cdf_file(cdf_file_path,log_file_path)
combined_data = combineFiles(tsv_data, combined_spec_data, mz_bins)


scan_start, scan_end = 32000, 36000
spec_acetyl = sum_intensity_for_scan_range(combined_data, scan_start, scan_end)


mz_acetyl = spec_acetyl[0]
A_acetyl = spec_acetyl[1]

N = 35
mzsmooth_acetyl = np.convolve(mz_acetyl,np.ones(N)/N, mode = 'same')
Asmooth_acetyl = np.convolve(A_acetyl,np.ones(N)/N, mode = 'same')


''' Make plot '''

fig, ax = plt.subplots()
ax.plot(mzsmooth_glu,Asmooth_glu/np.max(Asmooth_glu[1700:]), color = 'tab:blue')
ax.plot(mzsmooth_acetyl,Asmooth_acetyl/np.max(Asmooth_acetyl[1700:]), color = 'tab:green')
ax.plot(mzsmooth_nitro,Asmooth_nitro/np.max(Asmooth_nitro[1700:]), color = 'tab:red')
ax.set_xlim(200,500)
ax.set_ylim(0,1.1)
ax.set_xlabel('m/z')
ax.set_ylabel('intensity (arb.)')
ax.tick_params(direction = 'in')
plt.tight_layout()
